# Maintainer: Mateusz Mikuła <mati865@gmail.com>

_realname=sqlcipher
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.4.0
pkgrel=1
pkgdesc="SQLite extension that provides transparent 256-bit AES encryption of database files"
arch=('any')
url="https://www.zetetic.net/sqlcipher/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-tcl")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/${_realname}/${_realname}/archive/v${pkgver}.tar.gz"
        "02-fix-tcl-find.patch")
sha256sums=('0924b2ae1079717954498bda78a30de20ce2a6083076b16214a711567821d148'
            'd30c43a28eaeedcafde98d0f9a76fd8d676ee77732c9dc38e028147faa5adca0')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -p1 -i "${srcdir}"/02-fix-tcl-find.patch
  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${CARCH} ]] && rm -rf ${srcdir}/build-${CARCH}
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}

  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-tempstore=yes \
    --disable-tcl \
    --enable-json1 \
    --enable-fts4 \
    --enable-fts5 \
    --enable-rtree \
    --enable-session \
    --disable-editline \
    --enable-readline \
    --with-readline-lib="-L${MINGW_PREFIX}/lib -lreadline" \
    --with-readline-inc="-I${MINGW_PREFIX}/include" \
    CFLAGS="$CFLAGS -DSQLITE_HAS_CODEC -DSQLITE_ENABLE_COLUMN_METADATA" \
    LDFLAGS="$LDFLAGS -lcrypto"

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install

  cd "${srcdir}"/${_realname}-${pkgver}
  install -Dm644 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
